$(function () {
    $("#register_pasw2").focusout(function () {
        $pass1 = $("#register_pasw1");
        if($(this).val() === $pass1.val() && $pass1.val().length !== 0 && $(this).val().length !== 0){
            var encrypt = new JSEncrypt();
            encrypt.setPublicKey("-----BEGIN PUBLIC KEY-----\n" +
                "MIGeMA0GCSqGSIb3DQEBAQUAA4GMADCBiAKBgGDXzy1N5kQ49wm2Y6eMBGiojNbF\n" +
                "6ZowOmBmMA7tdkAIv1oxbSu/bf9xCJFZjoj+KCyf2+6C0JvTBm7022tt+U+pSKXS\n" +
                "3yEh+c0s+PaKJNjO9CFZwtF5B5x0c7bFWTHCwQyC6G/w9BhMN4TegL1cO8ut0d3o\n" +
                "7QQrDUN4n9n7uArnAgMBAAE=\n" +
                "-----END PUBLIC KEY-----");
            /*rsa加密*/
            $pass1.val(encrypt.encrypt($pass1.val()));
            $(this).val(encrypt.encrypt($(this).val()));
            return true;
        }else{
            $("#hint span").text("两次密码不同");
            $("#hint").fadeIn();
            return false;
        }
    }).focus(function () {
        $("#hint").fadeOut();
        $(this).val("");
    })


    $("#register_pasw1").focusout(function () {
        /*验证规则*/
        //密码强度正则，最少5位，包括至少1个大写字母，1个小写字母，1个数字，1个特殊字符
        var pPattern = /^.*(?=.{5,})(?=.*\d)(?=.*[A-Z])(?=.*[a-z])(?=.*[!@#$%^&*? ]).*$/;
        //输出 true
        $passwprd = $(this).val();
        if(!pPattern.test($passwprd)){
            $("#hint span").text("密码不符合规则");
            $("#hint").fadeIn();
        }
    }).focus(function () {
        $(this).val("");
        $("#register_pasw2").val("");
        $("#hint").fadeOut();
    })


    /*提示hint*/
    $(function () { $("[data-toggle='tooltip']").tooltip(); });
    $("#register_nickname").focusout(function () {
        var json = {
            nickname: $(this).val()
        };
        $.ajax({
            url:    "/registerCheckName",
            type:   "GET",
            timeout: 3000,
            contentType:"application/json;charset=utf-8",
            data: json,
            // JSON.stringify(json)
            success:function (msg) {
                if(msg){
                    console.log(msg);
                    document.querySelector("#nameError").style.display="none";
                    document.querySelector("#nameSuccess").style.display="block";
                }else{
                    console.log(msg);
                    document.querySelector("#nameSuccess").style.display="none";
                    document.querySelector("#nameError").style.display="block";
                }
            },
            error:function () {
                console.log("请求失败");
            }
        })
    }).focusin(function () {
        $("#hint").fadeOut();
    })

    $("#register_email").focusin(function () {
        $("#hint").fadeOut();
    })



})
